
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 12/07/2011 22:56:18
-- Generated from EDMX file: E:\Projetos\Pos_Projeto\Pos_Projeto\Pos_Projeto\Model.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [Database];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_CodigoProjeto]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Iteracoes] DROP CONSTRAINT [FK_CodigoProjeto];
GO
IF OBJECT_ID(N'[dbo].[FK_TarefasCodigoProjeto]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Tarefas] DROP CONSTRAINT [FK_TarefasCodigoProjeto];
GO
IF OBJECT_ID(N'[dbo].[FK_IteracoesTarefas]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Tarefas] DROP CONSTRAINT [FK_IteracoesTarefas];
GO
IF OBJECT_ID(N'[dbo].[FK_TarefasApontamentos]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Apontamentos] DROP CONSTRAINT [FK_TarefasApontamentos];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[Projetos]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Projetos];
GO
IF OBJECT_ID(N'[dbo].[Iteracoes]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Iteracoes];
GO
IF OBJECT_ID(N'[dbo].[Tarefas]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Tarefas];
GO
IF OBJECT_ID(N'[dbo].[Apontamentos]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Apontamentos];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'Projetos'
CREATE TABLE [dbo].[Projetos] (
    [CodigoProjeto] int IDENTITY(1,1) NOT NULL,
    [NomeProjeto] nvarchar(150)  NOT NULL,
    [ObjetivoProjeto] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'Iteracoes'
CREATE TABLE [dbo].[Iteracoes] (
    [CodigoIteracao] int IDENTITY(1,1) NOT NULL,
    [CodigoProjeto] int  NOT NULL,
    [NomeIteracao] nvarchar(150)  NOT NULL,
    [DataInicioIteracao] datetime  NOT NULL,
    [DataTerminoIteracao] datetime  NOT NULL
);
GO

-- Creating table 'Tarefas'
CREATE TABLE [dbo].[Tarefas] (
    [CodigoTarefa] int IDENTITY(1,1) NOT NULL,
    [CodigoProjeto] int  NOT NULL,
    [CodigoIteracao] int  NOT NULL,
    [NomeTarefa] nvarchar(150)  NOT NULL,
    [TipoTarefa] nvarchar(50)  NOT NULL,
    [HorasPrevistas] decimal(18,2)  NOT NULL,
    [ValorNegocio] bigint  NOT NULL,
    [SituacaoTarefa] nvarchar(50)  NOT NULL
);
GO

-- Creating table 'Apontamentos'
CREATE TABLE [dbo].[Apontamentos] (
    [CodigoApontamento] int IDENTITY(1,1) NOT NULL,
    [DataAtividade] datetime  NOT NULL,
    [HorasRealizadas] decimal(18,2)  NOT NULL,
    [CodigoTarefa] int  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [CodigoProjeto] in table 'Projetos'
ALTER TABLE [dbo].[Projetos]
ADD CONSTRAINT [PK_Projetos]
    PRIMARY KEY CLUSTERED ([CodigoProjeto] ASC);
GO

-- Creating primary key on [CodigoIteracao] in table 'Iteracoes'
ALTER TABLE [dbo].[Iteracoes]
ADD CONSTRAINT [PK_Iteracoes]
    PRIMARY KEY CLUSTERED ([CodigoIteracao] ASC);
GO

-- Creating primary key on [CodigoTarefa] in table 'Tarefas'
ALTER TABLE [dbo].[Tarefas]
ADD CONSTRAINT [PK_Tarefas]
    PRIMARY KEY CLUSTERED ([CodigoTarefa] ASC);
GO

-- Creating primary key on [CodigoApontamento] in table 'Apontamentos'
ALTER TABLE [dbo].[Apontamentos]
ADD CONSTRAINT [PK_Apontamentos]
    PRIMARY KEY CLUSTERED ([CodigoApontamento] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [CodigoProjeto] in table 'Iteracoes'
ALTER TABLE [dbo].[Iteracoes]
ADD CONSTRAINT [FK_CodigoProjeto]
    FOREIGN KEY ([CodigoProjeto])
    REFERENCES [dbo].[Projetos]
        ([CodigoProjeto])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_CodigoProjeto'
CREATE INDEX [IX_FK_CodigoProjeto]
ON [dbo].[Iteracoes]
    ([CodigoProjeto]);
GO

-- Creating foreign key on [CodigoProjeto] in table 'Tarefas'
ALTER TABLE [dbo].[Tarefas]
ADD CONSTRAINT [FK_TarefasCodigoProjeto]
    FOREIGN KEY ([CodigoProjeto])
    REFERENCES [dbo].[Projetos]
        ([CodigoProjeto])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TarefasCodigoProjeto'
CREATE INDEX [IX_FK_TarefasCodigoProjeto]
ON [dbo].[Tarefas]
    ([CodigoProjeto]);
GO

-- Creating foreign key on [CodigoIteracao] in table 'Tarefas'
ALTER TABLE [dbo].[Tarefas]
ADD CONSTRAINT [FK_IteracoesTarefas]
    FOREIGN KEY ([CodigoIteracao])
    REFERENCES [dbo].[Iteracoes]
        ([CodigoIteracao])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_IteracoesTarefas'
CREATE INDEX [IX_FK_IteracoesTarefas]
ON [dbo].[Tarefas]
    ([CodigoIteracao]);
GO

-- Creating foreign key on [CodigoTarefa] in table 'Apontamentos'
ALTER TABLE [dbo].[Apontamentos]
ADD CONSTRAINT [FK_TarefasApontamentos]
    FOREIGN KEY ([CodigoTarefa])
    REFERENCES [dbo].[Tarefas]
        ([CodigoTarefa])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TarefasApontamentos'
CREATE INDEX [IX_FK_TarefasApontamentos]
ON [dbo].[Apontamentos]
    ([CodigoTarefa]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------